package Day15;

import java.io.*;

public class Text1 {
    public static void main(String[] args) throws IOException {
        //问题是：拷贝文件
        //建立数据源
        File src = new File("D:\\aaaa\\src");
        //建立目的地
        File dest = new File("D:\\aaaa\\dest");
        copydiir(src,dest);
    }
    private static void copydiir(File src,File dest) throws IOException {
        //遍历文件
        //判断是文件还是文件夹
        File[] files = src.listFiles();
        for(File file: files){
            if(file.isFile()){
                //是文件，就拷贝
                //用字节流来拷贝
                FileInputStream fos = new FileInputStream(file);
                FileOutputStream fis = new FileOutputStream(new File(dest,file.getName()));
                byte[] bytes = new byte[1024];
                int len;
                while((len = fos.read(bytes)) != -1){
                    fis.write(bytes);
                }
                fis.close();
                fos.close();
            }
            else{
                //判断是文件夹,递归
                copydiir(file,new File(dest,file.getName()));
            }
        }
    }
}
